package com.kai.controller;

import com.kai.JwtUtil.JwtUtil;
import com.kai.entity.User;
import com.kai.mapper.UserMapper;
import com.kai.properties.JwtTokenProperties;
import com.kai.constant.UserConstant;
import com.kai.dto.RegisterDTO;
import com.kai.result.Result;
import com.kai.service.UserService;
import com.kai.vo.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/express/user")
@Slf4j
@ConfigurationProperties(prefix = "jwt.token")
@Tag(name = "用户接口")
public class UserController {

    @Autowired
    private UserService userService;


    //注册
    @PostMapping("/register")
    @Operation(summary = "用户注册接口")
    public Result<Void> register(@RequestBody RegisterDTO registerDTO) {
        log.info("用户注册：{}", registerDTO);
        userService.register(registerDTO);
        return Result.success();
    }


    //登录
    @GetMapping("/login")
    @Operation(summary = "用户登录接口")
    public Result<LoginVO> login(@RequestParam String userName, @RequestParam String password) {
        log.info("用户登录：{},{}", userName, password);
        LoginVO loginVo = userService.login(userName, password);
        return Result.success(loginVo);
    }

    @PutMapping("/update")
    @Operation(summary = "用户信息修改接口")
    public Result<Void> update(@RequestBody User user) {
        log.info("用户信息修改：{}", user);
        userService.update(user);
        return Result.success();
    }


}

